package com.xvyy.tingshu.order.config;

import com.xvyy.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * ClassName: OrderInfoAutoConfiguration
 * Package: com.xvyy.tingshu.order.config
 *
 * @Description:
 * @Author: xvyy
 * @Create: 2025/2/14 - 17:05
 * @Version: v1.0
 */
@Configuration
public class OrderInfoAutoConfiguration {


    /**
     * 延迟交换机
     *
     * @return
     */
    @Bean
    public CustomExchange customExchange() {
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER, "x-delayed-message", true, false, arguments);
    }

    /**
     * 延迟队列
     * exclusive ：是否排他
     *
     * @return
     */
    @Bean
    public Queue delayQueue() {
        return new Queue(MqConst.QUEUE_CANCEL_ORDER, true, false, false);
    }

    /**
     * 延迟队列绑定
     *
     * @return
     */
    @Bean
    public Binding binding(CustomExchange customExchange, Queue delayQueue) {
        return BindingBuilder.bind(delayQueue).to(customExchange).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }
}
